package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.First;
import live.jialing.core.beanvalidator.Second;
import live.jialing.data.core.JpaDomainEntity;
import live.jialing.structure.domain.Employee;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 教师：员工 - 学校 - 班级的关系。只有在班级中的员工才是老师，学校其他成员为员工
 * <p>
 * 同一个员工在班级中可能有多条记录。如任多门课程，或即时班主任也是任课老师
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "base_teacher")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Teacher.class)
public class Teacher extends JpaDomainEntity<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 职工
     */
    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @NotNull(message = "职工不能为空", groups = {First.class, Second.class})
    @JoinColumn(name = "employee_id",updatable = false,nullable = false)
    private Employee employee;

    /**
     * 在班中的职务
     */
    private String title;

    /**
     * 任课的科目/学科
     */
    private String subject;

    /**
     * 学校
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "school_id", updatable = false)
    @NotNull(message = "学校不能为空", groups = {First.class, Second.class})
    private School school;

    /**
     * 年级
     */
    @NotNull(message = "年级不能为空", groups = {First.class, Second.class})
    private Integer grade;

    /**
     * 班
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "class_id", updatable = false)
    @NotNull(message = "班不能为空", groups = {First.class, Second.class})
    private Squad squad;
}
